package com.ethank.enums.ali;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.ethank.entity.VoucherResponseVO;
import com.ethank.entity.VoucherResponseVOS;
import com.ethank.entity.billRecognize.CommonPrintedInvoiceBillDetails;
import com.ethank.enums.AliBillFieldEnum;

import java.util.*;

/**
 * @author tf
 * @date 2024-03-25
 * @Description
 */
public enum InvoiceFieldEnum {
    INVOICECODE("invoiceCode", "发票代码", "", 1, false),
    INVOICENUMBER("invoiceNumber", "发票号码", "", 1, false),
    PRINTEDINVOICECODE("printedInvoiceCode", "发票代码-机打", "", 1, false),
    PRINTEDINVOICENUMBER("printedInvoiceNumber", "发票号码-机打", "", 1, false),
    INVOICEDATE("invoiceDate", "开票日期", "", 1, false),
    MACHINECODE("machineCode", "机器编号", "", 1, false),
    CHECKCODE("checkCode", "校验码", "", 1, false),
    PURCHASERNAME("purchaserName", "购买方名称", "", 1, false),
    PURCHASERTAXNUMBER("purchaserTaxNumber", "购买方纳税人识别号", "", 1, false),
    PURCHASERCONTACTINFO("purchaserContactInfo", "受票方地址、电话", "", 1, false),
    PURCHASERBANKACCOUNTINFO("purchaserBankAccountInfo", "受票方开户行、账号", "", 1, false),
    PASSWORDAREA("passwordArea", "密码区", "", 1, false),
    INVOICEAMOUNTPRETAX("invoiceAmountPreTax", "不含税金额", "", 1, false),
    INVOICETAX("invoiceTax", "发票税额", "", 1, false),
    TOTALAMOUNTINWORDS("totalAmountInWords", "大写金额", "", 1, false),
    TOTALAMOUNT("totalAmount", "发票金额", "", 1, false),
    SELLERNAME("sellerName", "销售方名称", "", 1, false),
    SELLERTAXNUMBER("sellerTaxNumber", "销售方税号", "", 1, false),
    SELLERCONTACTINFO("sellerContactInfo", "销售方地址、电话", "", 1, false),
    SELLERBANKACCOUNTINFO("sellerBankAccountInfo", "销售方开户行、账号", "", 1, false),
    RECIPIENT("recipient", "收款人", "", 1, false),
    REVIEWER("reviewer", "复核人", "", 1, false),
    DRAWER("drawer", "开票人", "", 1, false),
    REMARKS("remarks", "备注", "", 1, false),
    TITLE("title", "标题", "", 1, false),
    FORMTYPE("formType", "发票联次", "", 1, false),
    INVOICETYPE("invoiceType", "发票类型", "", 1, false),
    SPECIALTAG("specialTag", "特殊标识信息", "", 1, false),
    INVOICEDETAILS("invoiceDetails","详情","",0,true);


    private final String key;
    private final String label;
    private final String value;
    private final Integer type;
    private final boolean require;

    InvoiceFieldEnum(String key, String label, String value, Integer type, boolean require) {
        this.key = key;
        this.label = label;
        this.value = value;
        this.type = type;
        this.require = require;
    }

    public String getKey() {
        return key;
    }

    public String getLabel() {
        return label;
    }

    public String getValue() {
        return value;
    }

    public Integer getType() {
        return type;
    }

    public boolean isRequire() {
        return require;
    }
    public static List<VoucherResponseVO> convertVoucher() {
        ArrayList<VoucherResponseVO> vos = new ArrayList<>();
        for (InvoiceFieldEnum fieldEnum : InvoiceFieldEnum.values()) {
            VoucherResponseVO vo = new VoucherResponseVO();
            vo.setKey(fieldEnum.getKey());
            vo.setLabel(fieldEnum.getLabel());
            vo.setType(fieldEnum.getType());
            if(fieldEnum.getKey().equals("invoiceDetails")){
                System.out.println("@@@@@"+fieldEnum.getKey());
                // CommonPrintedInvoiceBillDetails details = new CommonPrintedInvoiceBillDetails();
               // Map<String,Object> from = JSON.parseObject(details.toString(), new TypeReference<Map<String, Object>>(){});
                Map<String,Object> from = new HashMap<>();
                from.put("itemName","");
                from.put("unit","");
                from.put("quantity","");
                from.put("unitPrice","");
                from.put("amount","");
                Set<String> strings = from.keySet();
                List<VoucherResponseVO> responseVos = new ArrayList<>();
                for (String chilKey : strings) {
                    VoucherResponseVO childVo = AliBillFieldEnum.convertVoucherVO(chilKey,
                           "");
                    responseVos.add(childVo);
                }
                VoucherResponseVOS voucherResponseVOS = new VoucherResponseVOS();
                voucherResponseVOS.setItems(responseVos);
                ArrayList<VoucherResponseVOS> itemList = new ArrayList<>();
                itemList.add(voucherResponseVOS);
                vo.setChildren(itemList);
            //     List<VoucherResponseVO> voucherResponseVOS = InvoiceItemEnum.convertVoucher();
            //     vo.setChildren(voucherResponseVOS);
            }
            vos.add(vo);
        }
        return vos;
    }
}
